﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Networking
{
	public abstract class GameEvent
	{
        public NetworkPlayer Originator { get; private set; }
        public NetworkPlayer Target { get; private set; }

        public enum GameEventType
        {
            PlayerAttack,
            PlayerHit,
            PlayerDeath
        }

        public GameEventType EventType { get; private set; }


        public GameEvent(NetworkPlayer originator, NetworkPlayer target, GameEventType eventType)
        {
            Originator = originator;
            Target = target;
            EventType = eventType;
        }

        public GameEvent(GameEventType gameEventType, BitStream stream)
        {
            this.EventType = gameEventType;

            NetworkPlayer originator = new NetworkPlayer();
            NetworkPlayer target = new NetworkPlayer();

            stream.Serialize(ref originator);
            stream.Serialize(ref target);

            Originator = originator;
            Target = target;
        }

        public void SerializeForStream(BitStream stream)
        {
            int eventType = (int)this.EventType;
            stream.Serialize(ref eventType);

            NetworkPlayer originator = Originator;
            NetworkPlayer target = Target;

            stream.Serialize(ref originator);
            stream.Serialize(ref target);

            SerializeEventData(stream);

        }

        protected abstract void SerializeEventData(BitStream stream);


	}
}
